package com.neu.service;

import com.github.pagehelper.PageHelper;
import com.neu.dao.ShoppingCategoryMapper;
import com.neu.domain.ShoppingCategory;
import com.neu.domain.ShoppingCategoryExample;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class ShoppingCategoryService {
	
	 /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table shopping_category
     *
     * @mbg.generated
     */
	@Autowired
	private ShoppingCategoryMapper  shoppingCategoryMapper;
  
	//分页查询 
//	public List<ShoppingCategory>  queryByPid(String name, Integer page, Integer limit, String sort, String order){
//		ShoppingCategoryExample example = new ShoppingCategoryExample();
//		ShoppingCategoryExample.Criteria criteria = example.createCriteria();
//		  //判断根据传值进行模糊查询
//		  if (!StringUtils.isEmpty(name)) {
//	            criteria.andNameLike("%" + name + "%");
//	        }
//		  
//		  if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
//	            example.setOrderByClause(sort + " " + order);
//	        }
//	        criteria.andDeletedEqualTo(false);
//	        //分页
//	        PageHelper.startPage(page, limit);
//	        
//	        return shoppingCategoryMapper.selectByExample(example);
//	}
	 public List<ShoppingCategory> queryByPid(Integer pid) {
	        ShoppingCategoryExample example = new ShoppingCategoryExample();
	        example.or().andPidEqualTo(pid).andDeletedEqualTo(false);
	        return shoppingCategoryMapper.selectByExample(example);
	    }
	//添加
	public void add(ShoppingCategory sy) {
		 sy.setAddTime(LocalDateTime.now());
	     sy.setUpdateTime(LocalDateTime.now());
	     shoppingCategoryMapper.insertSelective(sy);
	}
	//更新
	public int updateById(ShoppingCategory sy) {
		 sy.setUpdateTime(LocalDateTime.now());
	     return shoppingCategoryMapper.updateByPrimaryKeySelective(sy);
	}
	//删除
	public  void deleteById(Integer id) {
		shoppingCategoryMapper.logicalDeleteByPrimaryKey(id);
	}
	//finByid
	   public ShoppingCategory findById(Integer id) {
	        return shoppingCategoryMapper.selectByPrimaryKey(id);
	    }
	//queryL1查询商品所属分类 
	   public List<ShoppingCategory> queryL1(){
		   ShoppingCategoryExample example = new ShoppingCategoryExample();
		   ShoppingCategoryExample.Criteria criteria = example.createCriteria();
		   example.or().andLevelEqualTo("L1").andDeletedEqualTo(false);
		   return shoppingCategoryMapper.selectByExample(example);
	   }
	
	

}
